package com.mrjy.live.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mrjy.common.entity.UserInfo;
import com.mrjy.common.entity.WisLessonInfo;
import com.mrjy.common.util.GlobalConstant;
import com.mrjy.live.bo.IWisLessonInfoBo;

@Controller()
@RequestMapping("live/wislessonInfo")
public class WisLessonInfoController{
	
	@Resource
	private IWisLessonInfoBo wisLessonInfoBo;
	
	
	
	@RequestMapping("/queryLessons")
	@ResponseBody
	public Object queryLessons(WisLessonInfo wisLessonInfo, HttpSession session){
		UserInfo userInfo = ((UserInfo) session.getAttribute(GlobalConstant.USER_INFO));
		return wisLessonInfoBo.queryLessons(wisLessonInfo, userInfo);
	}
	
	
	/**
	 * 创建课程
	 * @return
	 */
	@RequestMapping("/createLesson")
	@ResponseBody
	public Object createLesson(WisLessonInfo wisLessonInfo, HttpSession session){
		UserInfo userInfo = ((UserInfo) session.getAttribute(GlobalConstant.USER_INFO));
		return wisLessonInfoBo.addLesson(wisLessonInfo, userInfo);
	}
	
	/**
	 * 根据老师查询课程
	 * @return
	 */
	@RequestMapping("/queryLessonByTeacher")
	@ResponseBody
	public Object queryLessonByTeacher(WisLessonInfo wisLessonInfo, HttpSession session){
		UserInfo userInfo = ((UserInfo) session.getAttribute(GlobalConstant.USER_INFO));
		return wisLessonInfoBo.queryLessonByTeacherId(wisLessonInfo, userInfo);
	}
	
	/**
	 * 根据老师查询学校id
	 * @return
	 */
	@RequestMapping("/queryTeachers")
	@ResponseBody
	public Object queryTeachers(WisLessonInfo wisLessonInfo){
		return wisLessonInfoBo.queryTeachers(wisLessonInfo);
	}
	
	/**
	 * 删除课程
	 * @return
	 */
	@RequestMapping("/deleteLesson")
	@ResponseBody
	public Object deleteLesson(WisLessonInfo wisLessonInfo){
		String message="ok";
		try{
		wisLessonInfoBo.txDeleteLessonByLessonCode(wisLessonInfo);
		}catch(Exception e){
			message="error";
		}
		return message;
	}
	
	/**
	 * 修改课程
	 * @return
	 */
	@RequestMapping("/updateLesson")
	@ResponseBody
	public Object updateLesson(WisLessonInfo wisLessonInfo){
		return wisLessonInfoBo.updateLessonByCode(wisLessonInfo);
	}
	/**
	 * 修改课程在线人数
	 * @return
	 */
	@RequestMapping("/updateOnlinePeople")
	@ResponseBody
	public Object updateOnlinePeople(WisLessonInfo wisLessonInfo){
		return wisLessonInfoBo.updateOnlinePeople(wisLessonInfo);
	}
	
	/**
	 * 查询课信息
	 * @return
	 */
	@RequestMapping("/queryByLessonCode")
	@ResponseBody
	public Object queryByLessonCode(WisLessonInfo wisLessonInfo){
		return wisLessonInfoBo.queryByLessonCode(wisLessonInfo);
	}
	
	/**
	 * 查询房间在线人数和限制人数
	 * @return
	 */
	@RequestMapping("/queryLimitByLessonCode")
	@ResponseBody
	public Object queryLimitByLessonCode(WisLessonInfo wisLessonInfo){
		return wisLessonInfoBo.queryLimitByLessonCode(wisLessonInfo);
	}
	
	/**
	 * 关闭房间、删除服务器用户
	 * @return
	 */
	@RequestMapping("/checkRoomTime")
	@ResponseBody
	public Object checkRoomTime(WisLessonInfo wisLessonInfo,HttpServletRequest request){
		return wisLessonInfoBo.checkRoomTime(wisLessonInfo);
	}
}
